package com.example.mytayunapi.Service;

import com.example.mytayunapi.Entity.ordersInfo;
import com.example.mytayunapi.Mapper.ordersMapper;
import com.example.mytayunapi.Vo.ordersuserproducts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ordersServiceImpl implements ordersService{

    @Autowired
    private ordersMapper ordersmapper;

    @Override
    public ordersInfo insertOrderAndGetFullInfo(ordersInfo ordersInfo) {
        // 插入订单并获取自增主键
        int rowsAffected = ordersmapper.insertOrderAndGetKey(ordersInfo);
        if (rowsAffected > 0 && ordersInfo.getOrder_id() != null) {
            // 使用新生成的订单 ID 查询完整订单数据
            return ordersmapper.getOrderById(ordersInfo.getOrder_id());
        } else {
            // 插入失败处理
            throw new RuntimeException("Failed to insert order or retrieve generated key");
        }
    }

    @Override
    public List<ordersuserproducts> queryOrders(String School_degree) {
        return ordersmapper.queryOrders(School_degree);
    }

    @Override
    public ordersInfo SelectedByOrder_id(Integer order_id) {
        ordersInfo orders = ordersmapper.SelectedByOrder_id(order_id);
        return orders;
    }

    @Override
    public Integer updateById(ordersInfo orders) {
        return ordersmapper.updateById(orders);
    }

    @Override
    public List<ordersInfo> Selected_order_id(Integer Product_id) {
        return ordersmapper.Selected_order_id(Product_id);
    }

    @Override
    public List<ordersuserproducts> SelectedByOrder_Status(String School_degree) {
        return ordersmapper.SelectedByOrder_Status(School_degree);
    }

    @Override
    public List<ordersuserproducts> getUser(Integer order_id) {
        return ordersmapper.getUser(order_id);
    }

    @Override
    public List<ordersuserproducts> queryOrdersByOrderId(Integer order_id) {
        return ordersmapper.queryOrdersByOrderId(order_id);
    }

    @Override
    public List<ordersuserproducts> queryOrdersRefundsByOrderId(Integer order_id) {
        return ordersmapper.queryOrdersRefundsByOrderId(order_id);
    }
}
